from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-04 14:05:41.978962
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 04, Feb, 2022
Time: 14:05:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9660
Nobs: 557.000 HQIC: -48.3917
Log likelihood: 6529.92 FPE: 7.33332e-22
AIC: -48.6645 Det(Omega_mle): 6.24813e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351318 0.069398 5.062 0.000
L1.Burgenland 0.106169 0.042195 2.516 0.012
L1.Kärnten -0.110668 0.021928 -5.047 0.000
L1.Niederösterreich 0.192537 0.087619 2.197 0.028
L1.Oberösterreich 0.132688 0.087138 1.523 0.128
L1.Salzburg 0.254487 0.044621 5.703 0.000
L1.Steiermark 0.034490 0.058803 0.587 0.558
L1.Tirol 0.099196 0.047492 2.089 0.037
L1.Vorarlberg -0.070950 0.041984 -1.690 0.091
L1.Wien 0.018126 0.077639 0.233 0.815
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052010 0.150158 0.346 0.729
L1.Burgenland -0.041156 0.091299 -0.451 0.652
L1.Kärnten 0.040585 0.047447 0.855 0.392
L1.Niederösterreich -0.201073 0.189585 -1.061 0.289
L1.Oberösterreich 0.453178 0.188543 2.404 0.016
L1.Salzburg 0.283861 0.096548 2.940 0.003
L1.Steiermark 0.114292 0.127234 0.898 0.369
L1.Tirol 0.306071 0.102761 2.978 0.003
L1.Vorarlberg 0.023678 0.090842 0.261 0.794
L1.Wien -0.022084 0.167991 -0.131 0.895
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192027 0.035462 5.415 0.000
L1.Burgenland 0.088498 0.021562 4.104 0.000
L1.Kärnten -0.007530 0.011205 -0.672 0.502
L1.Niederösterreich 0.236745 0.044774 5.288 0.000
L1.Oberösterreich 0.169747 0.044527 3.812 0.000
L1.Salzburg 0.039237 0.022801 1.721 0.085
L1.Steiermark 0.024973 0.030048 0.831 0.406
L1.Tirol 0.081471 0.024269 3.357 0.001
L1.Vorarlberg 0.055025 0.021454 2.565 0.010
L1.Wien 0.121530 0.039674 3.063 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120315 0.035427 3.396 0.001
L1.Burgenland 0.043239 0.021540 2.007 0.045
L1.Kärnten -0.013838 0.011194 -1.236 0.216
L1.Niederösterreich 0.168309 0.044729 3.763 0.000
L1.Oberösterreich 0.336067 0.044484 7.555 0.000
L1.Salzburg 0.099797 0.022779 4.381 0.000
L1.Steiermark 0.109809 0.030019 3.658 0.000
L1.Tirol 0.090983 0.024245 3.753 0.000
L1.Vorarlberg 0.060991 0.021433 2.846 0.004
L1.Wien -0.015903 0.039635 -0.401 0.688
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127444 0.066785 1.908 0.056
L1.Burgenland -0.048717 0.040607 -1.200 0.230
L1.Kärnten -0.045608 0.021103 -2.161 0.031
L1.Niederösterreich 0.136555 0.084321 1.619 0.105
L1.Oberösterreich 0.166663 0.083857 1.987 0.047
L1.Salzburg 0.284582 0.042941 6.627 0.000
L1.Steiermark 0.057670 0.056589 1.019 0.308
L1.Tirol 0.156435 0.045704 3.423 0.001
L1.Vorarlberg 0.094715 0.040403 2.344 0.019
L1.Wien 0.073589 0.074717 0.985 0.325
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080832 0.052128 1.551 0.121
L1.Burgenland 0.024168 0.031695 0.763 0.446
L1.Kärnten 0.053296 0.016471 3.236 0.001
L1.Niederösterreich 0.190694 0.065815 2.897 0.004
L1.Oberösterreich 0.331467 0.065453 5.064 0.000
L1.Salzburg 0.033066 0.033517 0.987 0.324
L1.Steiermark 0.004246 0.044170 0.096 0.923
L1.Tirol 0.119813 0.035674 3.359 0.001
L1.Vorarlberg 0.066395 0.031536 2.105 0.035
L1.Wien 0.098004 0.058319 1.680 0.093
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174167 0.062928 2.768 0.006
L1.Burgenland 0.003189 0.038261 0.083 0.934
L1.Kärnten -0.065619 0.019884 -3.300 0.001
L1.Niederösterreich -0.113404 0.079451 -1.427 0.153
L1.Oberösterreich 0.214801 0.079014 2.719 0.007
L1.Salzburg 0.053626 0.040461 1.325 0.185
L1.Steiermark 0.249241 0.053321 4.674 0.000
L1.Tirol 0.498870 0.043065 11.584 0.000
L1.Vorarlberg 0.065445 0.038070 1.719 0.086
L1.Wien -0.076831 0.070401 -1.091 0.275
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158409 0.069685 2.273 0.023
L1.Burgenland -0.004249 0.042370 -0.100 0.920
L1.Kärnten 0.061898 0.022019 2.811 0.005
L1.Niederösterreich 0.173066 0.087982 1.967 0.049
L1.Oberösterreich -0.064943 0.087498 -0.742 0.458
L1.Salzburg 0.205911 0.044805 4.596 0.000
L1.Steiermark 0.139067 0.059046 2.355 0.019
L1.Tirol 0.057388 0.047689 1.203 0.229
L1.Vorarlberg 0.144036 0.042158 3.417 0.001
L1.Wien 0.132688 0.077961 1.702 0.089
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.396077 0.040691 9.734 0.000
L1.Burgenland -0.003296 0.024741 -0.133 0.894
L1.Kärnten -0.020789 0.012857 -1.617 0.106
L1.Niederösterreich 0.200718 0.051375 3.907 0.000
L1.Oberösterreich 0.239293 0.051093 4.684 0.000
L1.Salzburg 0.034434 0.026163 1.316 0.188
L1.Steiermark -0.019231 0.034479 -0.558 0.577
L1.Tirol 0.088345 0.027847 3.173 0.002
L1.Vorarlberg 0.051647 0.024617 2.098 0.036
L1.Wien 0.036225 0.045523 0.796 0.426
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035091 0.104210 0.168882 0.134410 0.095875 0.081354 0.030604 0.212824
Kärnten 0.035091 1.000000 -0.025308 0.132808 0.046784 0.085993 0.444773 -0.068155 0.093643
Niederösterreich 0.104210 -0.025308 1.000000 0.308182 0.123439 0.267657 0.065222 0.155940 0.281701
Oberösterreich 0.168882 0.132808 0.308182 1.000000 0.215765 0.294493 0.169892 0.134774 0.236376
Salzburg 0.134410 0.046784 0.123439 0.215765 1.000000 0.124862 0.089979 0.104332 0.128561
Steiermark 0.095875 0.085993 0.267657 0.294493 0.124862 1.000000 0.134387 0.106400 0.030142
Tirol 0.081354 0.444773 0.065222 0.169892 0.089979 0.134387 1.000000 0.063907 0.152545
Vorarlberg 0.030604 -0.068155 0.155940 0.134774 0.104332 0.106400 0.063907 1.000000 -0.003170
Wien 0.212824 0.093643 0.281701 0.236376 0.128561 0.030142 0.152545 -0.003170 1.000000